export const AUTHORIZATION_TOKEN = "x-access-token";

export const ROUTE_PATHS = {
  login: "/login",
  register: "/register",
  notFound: "/not-found",
  user: "/user",
  userAccount: "/user/account/:id",
  material: "/material",
  order: "/order",
  orderDetail: "/order/detail/:id",
};
export const PATH_TITLE_MAP = {
  [ROUTE_PATHS.user]: "用户管理",
  [ROUTE_PATHS.userAccount]: "账号管理",
  [ROUTE_PATHS.material]: "素材管理",
  [ROUTE_PATHS.order]: "商单管理",
  [ROUTE_PATHS.orderDetail]: "商单详情",
};

export const matchRoutePath = (currentPath: string): string | null => {
  if (PATH_TITLE_MAP[currentPath as keyof typeof PATH_TITLE_MAP]) {
    return currentPath;
  }

  // 匹配动态路由
  const dynamicRouteMatch = Object.keys(PATH_TITLE_MAP).find((routePath) => {
    const regexPattern = routePath.replace(/:\w+/g, "[^/]+");
    const regex = new RegExp(`^${regexPattern}$`);
    return regex.test(currentPath);
  });

  return dynamicRouteMatch || null;
};

export const getPathTitle = (path: string): string | undefined => {
  const matchedPath = matchRoutePath(path);
  return matchedPath ? PATH_TITLE_MAP[matchedPath as keyof typeof PATH_TITLE_MAP] : undefined;
};
